/*
 * modbus.h
 *
 *  Created on: Nov 12, 2024
 *      Author: zxx
 */

#ifndef MODBUS_H_
#define MODBUS_H_
#include "main.h"
#include "crc16.h"
#include "app.h"
#include "usart.h"

#define MB_SER_PDU_SIZE_MAX     256     /*!< Maximum size of a Modbus RTU frame. */
#define MB_SER_PDU_SIZE_CRC     2       /*!< Size of CRC field in PDU. */
#define MB_SER_PDU_ADDR_OFF     0       /*!< Offset of slave address in Ser-PDU. */
#define MB_SER_PDU_PDU_OFF      1       /*!< Offset of Modbus-PDU in Ser-PDU. */


#define MODBUS_BUFFSIZE	100
void Modbus_Event();
void Modbus_Init();
extern uint8_t From_Flag;


typedef struct
{
  uint8_t  myadd;        //本设备从机地址
	uint8_t  rcbuf[MODBUS_BUFFSIZE];   //modbus接受缓冲区
	uint8_t  timout;       //modbus数据持续时间
	uint8_t  recount;      //modbus端口接收到的数据个数
	uint8_t  timrun;       //modbus定时器是否计时标志
	uint8_t  reflag;       //modbus一帧数据接受完成标志位
	uint8_t  sendbuf[MODBUS_BUFFSIZE]; //modbus接发送缓冲区

}MODBUS;

#endif /* MODBUS_H_ */
